package io.gitee.xyuesheng.day01;

import org.junit.Test;

import java.util.Scanner;

public class HomeworkTaskControl {
    @Test
    //输入输出
    public void test1() {
        Scanner in = new Scanner(System.in);
        System.out.println("请输入数字");
        int a = in.nextInt();
        int b = 2;
        int c = a / b + 1;
        System.out.println("c=" + c + "");
    }

    @Test
//每月天数计算
    public void test2() {
        Scanner in = new Scanner(System.in);
        System.out.println("请输入年份");
        int year = in.nextInt();
        System.out.println("请输入月份");
        int month = in.nextInt();
        switch (month) {
            case 1:
            case 3:
            case 5:
            case 7:
            case 8:
            case 10:
            case 12:
                System.out.println("31");
                break;
            case 4:
            case 6:
            case 9:
            case 11:
                System.out.println("30");
                break;
            case 2:
                if (year % 4 == 0 && year % 100 != 0) {
                    System.out.println("29");
                } else {
                    System.out.println("28");
                }
                break;
        }
    }

    @Test
//计算一元二次方程
    public void test3() {
        Scanner in = new Scanner(System.in);
        System.out.println("请输入a");
        int a = in.nextInt();
        System.out.println("请输入b");
        int b = in.nextInt();
        System.out.println("请输入c");
        int c = in.nextInt();
        double d = Math.pow(b, 2) - 4 * a * c;
        if (d < 0) {
            System.out.println("方程无实数解");
        } else {
            double x1 = ((-b) + Math.sqrt(Math.pow(b, 2) - 4 * a * c)) / 2 * a;
            double x2 = ((-b) - Math.sqrt(Math.pow(b, 2) - 4 * a * c)) / 2 * a;
        }
    }

    @Test
//求最大公约数
    public void test4() {
        Scanner in = new Scanner(System.in);
        System.out.println("请输入较小数a");
        int a = in.nextInt();
        System.out.println("请输入较大数b");
        int b = in.nextInt();
        int n = 0;
        for (int i = 2; i <= a; i++) {
            if (a % i == 0 && b % i == 0) {
                n = i;
            }
        }
        System.out.println(n);
    }

    @Test
//计算素数
    public void test5() {
        Scanner in = new Scanner(System.in);
        System.out.println("请输入数字");
        int a = in.nextInt();
        for (int i = 2; i < a; i++) {
            int flag = 1;
            if (a % i != 0) {

            } else {
                flag = 0;
                System.out.println(("a不是素数"));
                return;
            }
        }
        System.out.println("a是素数");
    }

    @Test
    public void test6() {
        for (int i = 2; i <= 100; i++) {
            int flag = 1;
            for (int j = 2; j < i; j++) {
                if (i % j == 0) {
                    flag = 0;
                    break;
                } else {
                    flag = 1;
                }
            }
            if (flag == 1) {
                System.out.println(i);
            }
        }
    }

    @Test
    public void test7() {
        int count = 0;
        for (int i = 2; i <= 1000; i++) {
            int flag = 1;

            for (int j = 2; j < i; j++) {
                if (i % j == 0) {
                    flag = 0;
                    break;
                } else {
                    flag = 1;
                }
            }
            if (flag == 1) {
                count++;
                System.out.println(i);
                if (count > 50) break;
            }
        }
    }

    @Test
//使用坐标法打印形状
    public void test8() {
        int a = 0;
        for (int y = -2; y < 3; y++) {
            for (int x = -2; x < 3; x++) {
                if (y == x || y == -x) {
                    System.out.print("*");
                    a++;
                    if (a % 5 == 0) {
                        System.out.println(" ");
                    }
                } else {
                    System.out.print(".");
                    a++;
                    if (a % 5 == 0) {
                        System.out.println(" ");
                    }
                }
            }
        }
    }

    @Test
    public void test9() {
        for (int y = -2; y < 3; y++) {
            for (int x = -2; x < 3; x++) {
                if (y == x || y == -x) {
                    System.out.print("*");
                } else {
                    System.out.print(".");
                }
            }
            System.out.println(" ");
        }
    }

    @Test
    public void test10() {
        for (int y = -2; y < 3; y++) {
            for (int x = -2; x < 3; x++) {
                if (x == -2 || x == 2 || y == 0 || y == x || y == -x) {
                    System.out.print("*");
                } else {
                    System.out.print(".");
                }
            }
            System.out.println(" ");
        }
    }

    @Test
    public void test11() {
        for (int y = -2; y < 3; y++) {
            for (int x = -2; x < 3; x++) {
                if (x == 0 || y == 0 || y == 1 && x == 1 || y == 1 && x == -1 ||
                        y == -1 && x == -1 || y == -1 && x == 1) {
                    System.out.print("*");
                } else {
                    System.out.print(".");
                }
            }
            System.out.println(" ");
        }
    }

    @Test
    public void test12() {
        int n = 2;
        for (int i = -n; i <= n; i++) {
            for (int j = n; j >= -n; j--) {
                if (Math.abs(i) + Math.abs(j) <= n) {
                    System.out.print("*");
                } else {
                    System.out.print(".");
                }
            }
            System.out.println(" ");
        }
    }

    @Test
//判断题
    public void test13() {
        int x = -1;
        boolean isPositive = x > 0;
        if (isPositive = true) {
            System.out.println("positive!");
        } else {
            System.out.println("Negetive!");
        }
    }

    @Test
    public void test15() {
        int year = 2018;
        if (year < 2018) {
            System.out.println("2017");
        }
    }
}
